package com.zj.easytotwitter.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.zj.easytotwitter.R;
import com.zj.easytotwitter.adapter.PolicyItemAdapter;
import com.zj.easytotwitter.app.EttApplication;
import com.zj.easytotwitter.constant.LocalConstant;
import com.zj.easytotwitter.util.DividerItemDecoration;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by ZJ on 2017/7/31 0031.
 */

public class PolicyItemFragment extends BaseFragment  implements PolicyItemAdapter.OnItemClickLitener{
    View view;
    int position;//当前fragment的位置
    private PolicyItemAdapter policyItemAdapter;
    private List<String> list;
    @BindView(R.id.listview)
    RecyclerView listRepairs;
    private List<String> catalogList=new ArrayList<>();
    private long time;


    @Override
    public View inflate(LayoutInflater inflater, ViewGroup container) {
        view = View.inflate(EttApplication.getContext(), R.layout.item_fragment,null);
        return view;
    }

    @Override
    public void initData() {
        //获取position
        Bundle mBundle = getArguments();
        position = mBundle.getInt("position");
        catalogList= (List<String>) mBundle.getSerializable("list");
        listRepairs.setLayoutManager(new LinearLayoutManager(getContext()));
        listRepairs.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL_LIST));

        /*iPolicyTotalPresenter=new IPolicyTotalPresenterImpl(this);
        //数据请求
        iPolicyTotalPresenter.policyClassifyList((int) catalogList.get(position).getId(), LocalConstant.CLASS_CODE_5);*/
        policyItemAdapter = new PolicyItemAdapter(getContext(),catalogList);
        listRepairs.setAdapter(policyItemAdapter);
        policyItemAdapter.setOnItemClickLitener(this);
    }


    @Override
    public void onItemClick(View view, int position) {
        //2秒内不能重复点击
        if (System.currentTimeMillis()-time<2000) {
            return;
        }
        time = System.currentTimeMillis();
        //Intent intent = new Intent(getActivity(), ComPolicyDetailActivity.class);
        //创建一个Bundle，用来在Activity间传递数据
        //Bundle bundle = new Bundle();
        //bundle.putLong("id", list.get(position).getId());
        //intent.putExtras(bundle);
        //startActivity(intent);
    }

   /* @Override
    public void ChangeClassify(List<InfomationCatalog> list) {
        this.list=list;
        policyItemAdapter.refreshItemAll(list);
        policyItemAdapter.notifyDataSetChanged();
    }*/

}
